package com.ChefApp.mobile;

import java.util.Vector;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TextView;

public class DailyPreview {
	
 /*Aus was besteht ein Rezept?*/
	//Url
	//Name
	//Description
	//Datum
	//Bild
	//Zutaten
	//Zubereitung
	 String url,title,subtitle,desc,date,preview,zubereitung,html,htmlpreview,imageurl;

	Bitmap image;
	 Vector<String> zutaten=null;
	TextView tv1;
	ImageView iv1;
	 TableLayout tl;
	
	 public String getImageurl() {
			return imageurl;
		}

	public void setImageurl(String imageurl) {
			this.imageurl = imageurl;
		}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSubtitle() {
		return subtitle;
	}

	public void setSubtitle(String subtitle) {
		this.subtitle = subtitle;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public Bitmap getImage() {
		return image;
	}

	public void setImage(Bitmap image) throws Exception {
		
		this.image = image;
	}

	public String getPreview() {
		return preview;
	}

	public void setPreview(String preview) {
		this.preview = preview;
	}

	public String getZubereitung() {
		return zubereitung;
	}

	public void setZubereitung(String zubereitung) {
		this.zubereitung = zubereitung;
	}

	public Vector<String> getZutaten() {
		return zutaten;
	}

	public void setZutaten(Vector<String> zutaten) {
		this.zutaten = zutaten;
	}

	

	DailyPreview (){
	 url=null;
	 title=null;
	 subtitle=null;
	 desc=null;
	 date=null;
	 image=null;
	 preview=null;
	 zubereitung=null;
	 html=null;
	 htmlpreview=null;
	 zutaten=new Vector<String>();
	 

}
DailyPreview (String url,String type) throws Exception {
	 this.url=url;
	 title=null;
	 subtitle=null;
	 desc=null;
	 date=null;
	 image=null;
	 preview=null;
	 zubereitung=null;
	 html=null;
	 htmlpreview=null;
	 zutaten=new Vector<String>();
	 imageurl=null;
	 createReceipe(type);

}


private void createReceipe(String type) throws Exception {
	// TODO Auto-generated method stub
	Document startseite=null;
	if (type.equals("daily")){
    
		startseite = Jsoup.connect(url).userAgent("Mozilla").get();
		
	Element link=null;
	Elements links=null,lin=null,li=null;
	String source ="",picUrl="";
	if (!"".equals(startseite)){	link = startseite.getElementById("teaser-rezepte-home-scrollbox");}
	if (!"".equals(link)){ links =link.children();}
	if (!"".equals(links)){ lin = links.first().children();}
	if (!"".equals(lin)){ li = lin.first().children();
	 source = li.attr("href");
	 picUrl = li.get(0).childNode(1).attr("src");
	source = source.substring(1, source.length());
	source = link.baseUri()+"/"+source;
	imageurl=picUrl;
	
 
	Bitmap bild=MyImageLoader.LoadImage(imageurl);
	setImage(bild);
	setUrl(source);
	setTitle(li.first().children().attr("title"));
	setPreview(li.first().children().attr("src"));
	
	}
	
	
	
	
	
	
	
	
	setHtmlPreview();
	
	
	}
	else if (type.equals("normal")) {
		
	}
	
}




public void setHtml(){
	
}

public void setHtmlPreview(){
	this.htmlpreview= "<html>\n<body>\n"
					   +"<img class=\"left\" src=\""+getPreview()+"\"/>"
					   +"<p class=\"title\">"+getTitle()+"</p>"
					   +"</body>\n</html>";
}

public String getHtml() {
	return html;
}

public String getHtmlpreview() {
	return htmlpreview;
}

}